[XEN] Remove a race condition in shadow mark_dirty code.
authorTim Deegan <Tim.Deegan@xensource.com>
Fri, 2 Mar 2007 13:46:39 +0000 (13:46 +0000)
committerTim Deegan <Tim.Deegan@xensource.com>
Fri, 2 Mar 2007 13:46:39 +0000 (13:46 +0000)
Signed-off-by: Tim Deegan <Tim.Deegan@xensource.com>
xen/arch/x86/mm/shadow/common.c

index 0c66bc18cf3fab245dc5f24a3057618b8ca1d5e0..5b96bd986ac3fb57fe0e0fdf889d3880f40d6f2c 100644 (file)
@@ -2912,7 +2912,16 @@ void sh_mark_dirty(struct domain *d, mfn_t gmfn)
      * can be called from __hvm_copy during emulation).
      * If the lock isn't held, take it for the duration of the call. */
     do_locking = !shadow_locked_by_me(d);
-    if ( do_locking ) shadow_lock(d);
+    if ( do_locking ) 
+    { 
+        shadow_lock(d);
+        /* Check the mode again with the lock held */ 
+        if ( unlikely(!shadow_mode_log_dirty(d)) )
+        {
+            shadow_unlock(d);
+            return;
+        }
+    }
 
     ASSERT(d->arch.paging.shadow.dirty_bitmap != NULL);